#define  _CRT_SECURE_NO_WARNINGS
#include <vector>
#include <queue>
using namespace std;

class Solution {
public:
    int lastStoneWeight(vector<int>& stones) {
        priority_queue<int> heap(stones.begin(), stones.end());
        while (heap.size() > 1)
        {
            int top1 = heap.top(); heap.pop();
            int top2 = heap.top(); heap.pop();
            heap.push(top1 - top2);
        }
        return heap.size() == 1 ? heap.top() : 0;
    }
};